tree grammar TreeGrammar;

options {
  ASTLabelType = CommonTree; 
  output       = template;
}

// Tokens used internally by Moca
// ID: ('a'..'z' | 'A'..'Z')+;
// STRING: ( ID | ('0'..'9') )+; 
// ATRIBUTE: Used as an imaginary token for coding attributes in XML files (ATTRIBUTE name=ID value=STRING)
tokens {
  ID;
  STRING;
  ATTRIBUTE;
} 
  
@header {
package org.moflon.moca.text.unparser;
}

// These are the grammar rules to parse
// the simple moca tree
main: ^('BOARD' rows+=row+) -> board(rows={$rows});

row: ^('ROW' columns+=column+) -> row(columns={$columns});

column: ^('COLUMN' t+=types?) -> column(type={$t});



types: 'KW_KingWhite' -> kw() |
       'QW_QueenWhite' -> qw() |
       'RW_RookWhite' -> rw() |
       'BW_BishopWhite' -> bw() |
       'NW_KnightWhite' -> nw() |
       'PW_PawnWhite' -> pw() |
       'KB_KingBlack' -> kb() |
       'QB_QueenBlack' -> qb() |
       'RB_RookBlack' -> rb() |
       'BB_BishopBlack' -> bb() |
       'NB_KnightBlack' -> nb() |
       'PB_PawnBlack' -> pb();
